import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UploadedFile,
  Put,
} from '@nestjs/common';

import { ContentService } from './content.service';
import { CreateContentDto } from './dto/create-content.dto';
import { UpdateContentDto } from './dto/update-content.dto';

@Controller('blog')
export class ContentController {
  constructor(private readonly contentService: ContentService) {}

  uploadFile(@UploadedFile() file) {
    console.log(file);
  }

  @Post('content/')
  create(@Body() createContentDto: CreateContentDto) {
    return this.contentService.create({...createContentDto,createTime:new Date().getTime()});
  }

  @Get('content/')
  findAll() {
    return this.contentService.findAll();
  }

  @Get('content/:id')
  findOne(@Param('id') id: string) {
    return this.contentService.findOne(+id);
  }

  @Put('content/:id')
  async update(@Param('id') id: string, @Body() updateContentDto: UpdateContentDto) {
    await this.contentService.update(+id, updateContentDto);
    return [updateContentDto]
  }

  @Delete('content/:id')
  remove(@Param('id') id: string) {
    return this.contentService.remove(Number(id));
  }

  @Get('classify/allClassify')
  findAllClassify() {
    return this.contentService.findAllClassify();
  }
}
